/**<P>Title:ucweb</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2010</p>
 *<p>Company: ucweb.com</p>
 *@author chensl@ucweb.com
 *@version 
 */
package com.ucweb.pooltest;
import java.util.ArrayList;

import com.ucweb.pooldemo.R;
import com.ucweb.pooltest.util.Setting;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * @author chensl@ucweb.com
 *
 * 下午2:36:02 2014-8-27
 */
public class ResultActivity extends ActionBarActivity {
	public static final String KEY_NORMAL_COST="normal";
	public static final String KEY_POOL_COST="pool";
	private ArrayList<Integer> mNormalCost,mPoolCost;
	private String[] itemTitles;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_main);
		getSupportActionBar().setDisplayShowHomeEnabled(true);
		Bundle args=getIntent().getExtras();
		mNormalCost=args.getIntegerArrayList(KEY_NORMAL_COST);
		mPoolCost=args.getIntegerArrayList(KEY_POOL_COST);
		Fragment resultFragment = new ResultFragment();
		String repeat=String.valueOf(Setting.getInstance().getAllocateCount());
		getSupportActionBar().setTitle(getString(R.string.title_result_repeat).replace("#", repeat));
		itemTitles=getResources().getStringArray(R.array.res_item_strs);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.main_content, resultFragment).commit();
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	class ResultFragment extends Fragment  {
		private TextView mTextViewNormal;
		private TextView mTextViewPool;
		@Override
		public View onCreateView(LayoutInflater inflater,
				@Nullable ViewGroup container,
				@Nullable Bundle savedInstanceState) {
			View view = inflater.inflate(R.layout.fragment_result,  container,false);
			mTextViewNormal=(TextView) view.findViewById(R.id.result_normal_txview_id);
			mTextViewPool=(TextView) view.findViewById(R.id.result_pool_txview_id);
			setNormalResultText();
			setPoolResultText();
			return view;
		}
		private void setPoolResultText() {
			StringBuilder sb=new StringBuilder();
			sb.append(getString(R.string.result_pool_cost)+"\n");
			for(int i=0;i<itemTitles.length;i++){
				sb.append("\t"+itemTitles[i]+"\t\t\t"+mPoolCost.get(i)+"\n\n");
			}
			mTextViewPool.setText(sb.toString());
			
		}
		private void setNormalResultText() {
			StringBuilder sb=new StringBuilder();
			sb.append(getString(R.string.result_normal_cost)+"\n");
			for(int i=0;i<itemTitles.length;i++){
				sb.append("\t"+itemTitles[i]+"\t\t\t"+mNormalCost.get(i)+"\n\n");
			}
			mTextViewNormal.setText(sb.toString());
		}
	}

}
